package com.zbs.framework.pay.controller;

import com.zbs.framework.pay.service.PayCallbackService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/pay")
@Slf4j
public class PayController {

//    @Autowired
//    private AliPayService aliPayService;
//    @Autowired
//    private AliPayNewService aliPayNewService;
    @Autowired
    private PayCallbackService payCallbackService;

//    @GetMapping("/alipay.do")
//    public byte[] aliPay() throws Exception {
//        String tradeNo = GenerateNum.generateOrder() + UUID.randomUUID().toString().substring(0, 5);
//        BigDecimal totalAmount = new BigDecimal("0.1");
//        QrCodeResponse qrCodeResponse = this.aliPayService.aliPay("测试11111", tradeNo, totalAmount, "30m");
//        return LogoUtil.getPayLogoByte(qrCodeResponse);
//    }
//
//    //
//    @GetMapping("/alipay2.do")
//    public byte[] aliPay2() throws Exception {
//        String tradeNo = GenerateNum.generateOrder() + UUID.randomUUID().toString().substring(0, 5);
//        BigDecimal totalAmount = new BigDecimal("99");
//        QrCodeResponse qrCodeResponse = aliPayNewService.createFaceToFace(tradeNo, tradeNo, totalAmount, "30m");
//        return LogoUtil.getPayLogoByte(qrCodeResponse);
//    }
//
//    @GetMapping("/alipay3.do")
//    public ResultData aliPay3(String outTradeNo,String tradeNo,String refundAmount)  throws Exception{
//        String response = this.aliPayNewService.refundTrade(tradeNo, outTradeNo, new BigDecimal(refundAmount));
//        return ResultUtil.ok(response);
//    }
//
//    @GetMapping("/alipay4.do")
//    public ResultData aliPay4(String outTradeNo,String tradeNo)  throws Exception{
//        AlipayCallbackModel response = this.aliPayNewService.queryTrade(tradeNo, outTradeNo);
//        return ResultUtil.ok(response);
//    }

    @PostMapping("/alipay/callback.do")
    private void callback(HttpServletRequest request) {
        this.payCallbackService.alipayCallback(request);
    }

}
